package com.learn.cloud.validator.annotation;


import com.learn.cloud.validator.constraints.GenderValidator;
import jakarta.validation.Constraint;
import jakarta.validation.Payload;

import java.lang.annotation.*;

import static java.lang.annotation.ElementType.*;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
 * @description: 性别校验
 * @author: cong zhi
 * @createDate: 2022/2/6 11:58
 * @updateUser: cong zhi
 * @updateDate: 2022/2/6 11:58
 * @updateRemark: 修改内容
 * @version: v1.0
 */
@Documented
@Constraint(validatedBy = {GenderValidator.class})
@Target({ElementType.FIELD, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface GenderValidation {
    /**
     * 默认错误消息
     */
    String message() default "性别取值范围不对!";

    /**
     * 支持枚举列表验证
     */
    Class<?> value();

    /**
     * 分组
     *
     * @return
     */
    Class<?>[] groups() default {};

    /**
     * 负载
     *
     * @return
     */
    Class<? extends Payload>[] payload() default {};

    /**
     * 是否必填
     * <p>
     * 如果必填，在校验的时候本字段没值就会报错
     */
    boolean required() default true;


    /**
     * Defines several {@code @GenderValidation} annotations on the same element.
     */
    @Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE})
    @Retention(RUNTIME)
    @Documented
    public @interface List {
        GenderValidation[] value();
    }
}
